﻿@using PlatformNetCore.Entity
@{
    ViewBag.Title = "基本资料";
}
@model Company

<div style="padding: 15px;">
    <!-- 内容主体区域 -->
    <div class="layui-card">
        <div class="layui-card-header">基本资料</div>
        <div class="layui-card-body">
            <form class="layui-form" id="applyForm" action="#" lay-filter="apply-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">网站名称：</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="ID" name="ID" autocomplete="on" value="@Model.ID" />
                        <input type="text" id="SiteName" name="SiteName" value="@Model.SiteName" placeholder="网站名称" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">公司名称：</label>
                    <div class="layui-input-block">
                        <input type="text" id="CompanyName" name="CompanyName" value="@Model.CompanyName" placeholder="公司名称" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item" id="previewImage">
                    <label class="layui-form-label">Logo图片：</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="LogoImage" value="@Model.LogoImage" name="LogoImage" autocomplete="on" class="layui-input">
                        <button type="button" class="layui-btn layui-btn-danger" id="transfer-upload">
                            <i class="layui-icon"></i>上传图片
                        </button>
                        @if (!string.IsNullOrWhiteSpace(Model.LogoImage))
                        {
                            <img id="transferImg" data-url="@Model.LogoImage" src="@Model.LogoImage" style="height:40px;cursor:pointer;">
                        }
                        else
                        {
                            <img id="transferImg" style="height:40px;display:none;">
                        }
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">备案号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="WebNumber" name="WebNumber" value="@Model.WebNumber" placeholder="备案号" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">服务热线：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ServicePhone" name="ServicePhone" value="@Model.ServicePhone" placeholder="服务热线" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">招聘投递简历邮箱：</label>
                    <div class="layui-input-block">
                        <input type="text" id="Email" name="Email" value="@Model.Email" placeholder="联系邮箱" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">联系电话：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ContactPhone" name="ContactPhone" value="@Model.ContactPhone" placeholder="联系电话" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                @*<div class="layui-form-item">
                    <label class="layui-form-label">服务邮箱：</label>
                    <div class="layui-input-block">
                        <input type="text" id="ServiceEmail" name="ServiceEmail" value="@Model.ServiceEmail" placeholder="服务邮箱" autocomplete="on" class="layui-input" />
                    </div>
                </div>*@
                <div class="layui-form-item">
                    <label class="layui-form-label">联系地址：</label>
                    <div class="layui-input-block">
                        <input type="text" id="Address" name="Address" value="@Model.Address" placeholder="联系地址" autocomplete="on" class="layui-input" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="btnSubmit" lay-submit lay-filter="submit-form">保存</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    var viewer = new Viewer(document.getElementById('previewImage'), {
        url: 'src',
        navbar: false
    });

    layui.use(['form', 'layer','upload'], function () {
        var layer = layui.layer, form = layui.form;
        var upload = layui.upload;

        form.render(null, 'apply-form');

        var iframeId = $(window.frameElement).attr("id");
        //设定文件大小限制
        var loadingFlag;
        upload.render({
            elem: '#transfer-upload'
            , url: '/Admin/File/Upload'
            , size: 10240 //限制文件大小 5M，单位 KB
            , data: { UploadFileType: "@(PlatformNetCore.Entity.UploadFileType.IconImage.ToString())" }
            , before: function (obj) {
                $(parent.document).find("#"+iframeId).parent().nextAll("div").find("a[class='layui-layer-btn0']").attr("disabled",true).css("pointer-events","none");
                loadingFlag = layer.msg('正在加载，请稍候……', { icon: 16, shade: 0.01, shadeClose: false, time: 10000 });
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#transferImg').attr('style', 'height:40px;cursor:pointer;');
                    $('#transferImg').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                layer.close(loadingFlag);
                $(parent.document).find("#"+iframeId).parent().nextAll("div").find("a[class='layui-layer-btn0']").removeAttr("disabled").removeAttr("style");
                if (res.success) {
                    $("#LogoImage").val(res.data);
                }
                else {
                    layer.msg('上传失败，请重试', { icon: 2, time: 1500 });
                }
            }
            ,error: function() {
                layer.msg('上传失败，请重试', { icon: 2, time: 1500 });
            }
        });

        form.on('submit(submit-form)', function (data) {
            //询问框
            layer.confirm('确认保存吗？', {
                btn: ['确定', '关闭'], //按钮
                title: '提示'
            }, function () {
                //禁用
                $("#btnSubmit").attr("disabled", true);
                var paras = data.field;
                var loadingFlag;
                $.ajax({
                    url: "/Admin/Basis/Company",
                    type: "POST",
                    data: paras,
                    beforeSend: function () {
                        //注意，layer.msg默认3秒自动关闭，如果数据加载耗时比较长，需要设置time
                        loadingFlag = layer.msg('正在处理，请稍候……', { icon: 16, shade: 0.01, shadeClose: false, time: 15000 });
                    },
                    success: function (response) {
                        //启用
                        layer.close(loadingFlag);
                        if (response.success) {
                            //保存成功
                            layer.msg('保存成功', { icon: 1, time: 1500 }, function () {
                                $("#btnSubmit").removeAttr("disabled");
                                window.location.href = "@Url.Action("Company", "Basis",new { area = "Admin"})";
                            });
                        } else {
                            $("#btnSubmit").removeAttr("disabled");
                            layer.msg(response.msg, { icon: 2, time: 5000 });
                        }
                    },
                    complete: function () {
                        layer.close(loadingFlag);
                    }
                });
            });
        });
    });
</script>
